package com.qf.mapper;

import com.qf.pojo.TbUser;
import com.qf.provider.MyUserProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author langazhe
 * @version V1.0
 * @Project mybatis02
 * @Package com.qf.mapper
 * @Description:
 * @Date 2022/5/18 21:36
 */
public interface UserMapper {
    @Select("SELECT * FROM tb_user WHERE id = #{id}")
    @ResultMap("usermap")//使用我们指定的resultmap 注意这个map必须定义在xml中
    TbUser findById(Long id);

    @Select("SELECT * FROM tb_user")
    List<TbUser> findAll();

    @Insert("INSERT INTO tb_user(username,password,email,gender,flag,role,code,nick_name)values(#{username},#{password},#{email},#{gender},#{flag},#{role},#{code},#{nickName})")
    int addUser(TbUser tbUser);

    @Update("<script>update tb_user\n" +
            "        <set>\n" +
            "            <if test=\"username != null and username !=''\">\n" +
            "                username=#{username},\n" +
            "            </if>\n" +
            "            <if test=\"email != null and email !=''\">\n" +
            "                email=#{email},\n" +
            "            </if>\n" +
            "            <if test=\"gender != null and gender !=''\">\n" +
            "                gender=#{gender},\n" +
            "            </if>\n" +
            "        </set>\n" +
            "        where id=#{id}</script>")
    int updateUser(TbUser tbUser);

    //告诉mybatis,我的sql语句是从MyUserProvider类中找updateUser名字的方法
    @UpdateProvider(value = MyUserProvider.class,method = "updateUser")
    int updateUser2(TbUser tbUser);


}
